import Qt 4.7

// MainView of the ChessBoard

Item {
        id: qml_item_chessBoard
        width: 600
        height: 600

        FontLoader { id: chessFont; source: "../../MERIFONT.TTF" }

        // ChessBoard is a 8x8 rectangle grid
        Grid {
            id: qml_grid_chessGrid
            columns: 8
            spacing: 0
            x: 0
            y: 0
            width: parent.width
            height: parent.height
            rows: 8

            // 64 ChessBoard tiles - from top left to buttom right
            Repeater {
                     model: 64
                     Rectangle {
                         id: chessCell
                         width: parent.parent.width / 8
                         height: parent.parent.height / 8
                         color:
                             ((Math.floor(index / 8) % 2) === 0)
                                 ?
                             (index % 2  === 1 ? "#D18B47" : "#FFCE9E") // light brown &
                                 :
                             (index % 2  === 0 ? "#D18B47" : "#FFCE9E") // dark brown

                         // handle click on piece - to show available moves
                         MouseArea {
                             id: mouseSquareArea
                             anchors.fill: parent
                             onReleased: {
                                board.showAndMove(index);
                             }
                         }
                     }

                 }
            Text { text: board.status ; font.pixelSize: parent.width / 8; font.family: chessFont.name }
        }


    onWidthChanged: {

        // maybe use .js script to do this OR use c++-property
//        newWidth = width;
//        do {
//            newWidth--;
//        }
//        while (newWidth % 8 > 0);

//        width = newWidth;
        height = width;
    }

    onHeightChanged: {
        console.log("height changed " + height);
        width = height;
    }

    // add chess control panel
    ChessPanel {
        id: chessPanel
    }

    // add chess control panel
    ChessSetPiece {
        id: chessSetPiece
        x: 0
        y: 26
    }

    // add search button
    ChessSearchMove {
        id: chessSearchMove
        x: 0
        y: 52
    }
}



